import html
import json


dispatchers = {}

def Button(text, onclick = None):
    t = html.Input(type = "button", value = text)
    if onclick:
        dispatchers[id(onclick), "click"] = onclick
        t.attrs["onclick"] = ("javascript:dynAjax(GANGES_API_ROOT, %s);" %
            (json.dump({"oid" : t.id, "handler" : [id(onclick), "click"]}),)
        )
    return t



div_report = html.Div(
    Button(">>", onclick = lambda oid, event: 'alert("hi");')
)


doc = html.Document("test",
    script_urls = ["/static/client/json.js", "/static/client/ajax.js"],
    body = [
        html.JScript('GANGES_API_ROOT = "http://foobar.com/api/";'),
        html.Table(
            html.Tr(
                html.Td(html.Div(id = "id_query"))
            ),
            html.Tr(
                html.Td(
                    div_report
                )
            )
        )
    ]
)


b = Button("hello", onclick = lambda oid: 'alert("hello");')
#print b.render().render()

txt = doc.render()
print txt

f = open("c:\\foo.html", "w")
f.write(txt)
f.close()
import os
os.system("start c:\\foo.html")











